namespace Wips.Domain.Models.Authorities.Model
{
    /// <summary>
    /// 组织机构
    /// </summary>
    [Table("AuthorityOrganizations")]
    [SugarTable("AuthorityOrganizations", "组织架构")]
    public class Organization : EntityBase, IAggregateRoot
    {

        /// <summary>
        /// 所属上级Id
        /// </summary>
        public string ParentId { get; set; }

        /// <summary>
        /// 所属上级
        /// </summary>
        [Navigate(NavigateType.ManyToOne, nameof(ParentId))]
        public Organization Parent { get; set; }

        /// <summary>
        /// 上级路径，用逗号分割，用于快速检索
        /// </summary>
        public string ParentPath { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [MaxLength(32)]
        [Required]
        public string Name { get; set; }

        /// <summary>
        /// 联系人姓名
        /// </summary>
        [MaxLength(32)]
        public string ContactName { get; set; }

        /// <summary>
        /// 联系人手机号
        /// </summary>
        [MaxLength(11)]
        public string ContactPhoneNumber { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [MaxLength(500)]
        public string Remarks { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public Status Status { get; set; }


        /// <summary>
        /// 最后更新人Id
        /// </summary>
        public string LastUpdatedUserId { get; set; }


        /// <summary>
        ///数据来源 0 本系统创建， 1 来源于中台系统 SHR
        /// </summary>
        public int SourceType { get; set; }


        /// <summary>
        /// 对方主键
        /// </summary>
        public string OtherId { get; set; }

        /// <summary>
        /// 部门编码
        /// </summary>
        public string DeptNumber { get; set; }

        /// <summary>
        /// 经度
        /// </summary>
        public string Longitude { get; set; }

        /// <summary>
        /// 纬度
        /// </summary>
        public string Latitude { get; set; }

        /// <summary>
        /// 地址
        /// </summary>
        public string Address { get; set; }



        /// <summary>
        /// 扩展备注
        /// </summary>
        public string ExtendRemarks { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public Organization()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="name"></param>
        /// <param name="contactName"></param>
        /// <param name="contactPhoneNumber"></param>
        /// <param name="remarks"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public Organization(
            string name = null,
            string contactName = null,
            string contactPhoneNumber = null,
            string remarks = null)
        {
            Name = name ?? throw new ArgumentNullException(nameof(name));
            ContactName = contactName;
            ContactPhoneNumber = contactPhoneNumber;
            Remarks = remarks;
        }

        /// <summary>
        /// 状态变更
        /// </summary>
        /// <param name="lastUpdatedUserId"></param>
        public void StatusChange(string lastUpdatedUserId)
        {
            Status = Status == Status.Disabled ? Status.Enabled : Status.Disabled;
            LastUpdatedUserId = lastUpdatedUserId;
            Updated = DateTime.Now;
        }
    }
}